﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
using System;

public class StartPanel : UIBase
{
    private static string path = "UI/StartPanel";
    private static UILayer layer = UILayer.Mid;

    private Transform progressBar;

    protected override void Awake()
    {
        base.Awake();
        Transform trs = transform.Find("Center");
        trs = transform.Find("Bottom");
        progressBar = trs.Find("Progress");
        progressBar.gameObject.SetActive(false);
    }

    public override void Open(params System.Object[] parameters)
    {
        AudioMgr.Instance.PlayBGM();
        EventDispatcher.Login_Register += WaitProgress;
        OpenUI<LoginPanel>(UIPanel.LoginPanel);
    }

    public override void Close()
    {
        EventDispatcher.Login_Register -= WaitProgress;
        DestroyImmediate(this.gameObject);
    }

    private void WaitProgress()
    {
        progressBar.gameObject.SetActive(true);
        Image bar = progressBar.Find("ProgressBar").GetComponent<Image>();
        bar.fillAmount = 0;
        bar.DOFillAmount(1f, 2f).onComplete = () =>
        {
            OpenUI<LobbyPanel>(UIPanel.LobbyPanel, UIPanel.StartPanel);
        };
    }
}
